import { EditModalProps, useModalHandler } from './useModalHandler';
import { rowLoadingKey } from './useModeModalBinder';

export default function useDetailDrawerHandler(props: EditModalProps = {}) {
  const modalHandler = useModalHandler(props);

  function showEdit(record: any) {
    return modalHandler.showModal('edit', record);
  }

  function showAdd(record?: any) {
    return modalHandler.showModal('add', record);
  }

  function showDetail(record?: any) {
    return modalHandler.showModal('detail', record);
  }

  const openBtn = (mode: string, row: any) => {
    return {
      loading: row ? row[rowLoadingKey] : false,
      onClick: () => modalHandler.showModal(mode, row),
    };
  };

  return {
    ...modalHandler,
    showDetail,
    showAdd,
    showEdit,
    openBtn,
  };
}
